package com.kgc.basicprovider.controller;


import com.kgc.basic.pojo.Customer;
import com.kgc.basic.remote.CustomerRemote;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.basicprovider.service.CustomerService;
import com.kgc.basicprovider.service.ImportExportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.Map;

@Controller
public class CustomerController implements CustomerRemote {

    private Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Autowired
    private CustomerService customerService;


    @Override
    public ResponseMsg selectCustomerByPage(@RequestBody Map<String, Object> map) {
        logger.info("CustomerController selectCustomerByPage params{}", map);
        ResponseMsg responseMsg = customerService.selectCustomerByPage(map);
        logger.debug("CustomerController selectCustomerByPage responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg insertCustomer(@RequestBody Customer customer) {
        logger.info("CustomerController insertCustomer params{}", customer);
        ResponseMsg responseMsg = customerService.insertCustomer(customer);
        logger.debug("CustomerController insertCustomer responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg updateCustomer(@RequestBody Customer customer) {
        logger.info("CustomerController updateCustomer params{}", customer);
        ResponseMsg responseMsg = customerService.updateCustomer(customer);
        logger.debug("CustomerController updateCustomer responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg deleteCustomer(@RequestParam("id") int id) {
        logger.info("CustomerController deleteCustomer params{}", id);
        ResponseMsg responseMsg = customerService.deleteCustomer(id);
        logger.debug("CustomerController deleteCustomer responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg selectCustomerByCode(String code) {
        logger.info("provider CustomerController selectCustomerByCode code:{}", code);
        ResponseMsg msg = customerService.selectCustomerByCode(code);
        logger.debug("provider CustomerController selectCustomerByCode msg:{}", msg);
        return msg;
    }

    @Override
    public ResponseMsg selectAllCustomer() {
        logger.info("provider CustomerController selectAllCustomer is start...");
        ResponseMsg msg = customerService.selectAllCustomer();
        logger.debug("provider CustomerController selectAllCustomer msg:{}", msg);
        return msg;
    }

    @Override
    public ResponseMsg getAllCustomerByData() {
        logger.info("provider getAllCustomerByData is start...");
        ResponseMsg msg = customerService.getAllCustomerByData();
        logger.debug("provider getAllCustomerByData msg:{}",msg);
        return msg;
    }


}
